<?php
namespace app\admin\controller;
use app\common\controller\Sendmsg;
use app\service\lifeapiService;
use app\service\roominfoService;
use printing\printDemo;
use think\Controller;
use think\facade\Db;
use think\facade\View;

ini_set('max_execution_time','0');
ini_set('memory_limit','1024M');
class Billtest extends Controller{
    public function orderrefund(){
		if(request()->isPost()){
			$data=request()->post();
			$orderinfo=Db::table("bill")->where("id",$data["id"])->find();
			$orderinfo["refund_money"]=$data["refund_money"];
			$orderinfo["out_order_no"]="";
			$api=new lifeapiService();
			$orderinfo["token"] = (new roominfoService())->communityToken($orderinfo['community_id']);
			$result=$api->refund(json_encode($orderinfo));
			echo "<pre>";
			var_dump($result);
			if($result->code=="10000"){
			
				Db::table("bill")->where("id",$data["id"])->update(["status"=>"REFUND"]);
				unset($orderinfo["token"]);
				//$orderinfo["refund_operator"]=session("name");
				//$res=Db::table("car_order_refund")->insert($orderinfo);
				return "退款成功";
			}else{
				return "退款失败";
			}
			
		}else{
			$orderid=request()->get("id");
			$orderinfo=Db::table("bill")->where("id",$orderid)->find();
			View::assign("orderinfo",$orderinfo);
			return View::fetch("order_refund");
		}
		
	}
	
	public function refund(){
		if(request()->post()){
			$data=request()->post();
			$data["out_order_no"]="";
			echo "<pre>";
			var_dump($data);
			$api=new apiServiceTest();
			$data["token"] = (new orderService())->token($data["parking_id"]);
			$result=$api->refund(json_encode($data));
			
			var_dump($result);
		}else{
			$communitylist = Db::table("community")->select()->toArray();
			View::assign('communitylist',$communitylist);
			return View::fetch("refund");
		}
		
	}
	
	public function test(){
		$data["order_no"]="2020081122001457051458927193";
		$data["out_order_no"]="";
		$data["out_refund_no"]="2006301858230010611202222023";
		$data["refund_reason"]="正常退款";
		$data["refund_money"]="92.80";
		$community_id="APR0KM8PL3301";
		$data["token"] = (new roominfoService())->communityToken($community_id);
		echo "<pre>";
	
		$api=new lifeapiService();
		
	
		$result=$api->refund(json_encode($data));
		var_dump($result);
	}
}